package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @Author: Miyako
 * @Date: 2024-07-30-14:39
 * @Description:
 */
public class JDBCDemo03 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306" +
                "/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia" +
                "/Shanghai&rewriteBatchedStatements=true","root","root");
        Statement statement = connection.createStatement();

        Scanner scanner = new Scanner(System.in);

        System.out.println("输入你要删除的用户名");
        String username = scanner.nextLine();
        System.out.println("输入密码");
        String password = scanner.nextLine();
        String sql = "delete from userinfo where username='"+username+"' and "+"password='"+password+"'";
        if (statement.executeUpdate(sql)==0){
            System.out.println("删除失败");
        }else {
            System.out.println("删除成功");
        }
        scanner.close();
        connection.close();
    }
}
